function flattenArray(data) {
  let result = [];
  console.log("data",data);
  data.forEach((item,ind) => {
      let it = {...item};
      it.children = [];
      it.sort=ind+1
      result.push(it);
      console.log("item-----",item)
      if (item.children && item.children.length > 0) {
          let childs=[]
          //更新排序
          item.children.map((child,index) => {
              let c= {...child}
              c.sort=index+1
              childs.push(c)
          })
          result = result.concat(this.flattenArray(childs));
      }
  });
  // console.log("result",result);
  return result;
}

function changeSort(data){

  return data.map(item => {

      if (item.children && item.children.length > 0) {
          let children = []
          item.children.map((child,index) => {
              let c= {...child}
              c.sort=index+1
              console.log("---c: ",c)
              children.push(c)
              this.changeSort(children)
          })
          item.children = children
          // result = result.concat(this.changeSort(children));
          return item
      }
      
  });
  // console.log("result",result);
}

export default {
  flattenArray,changeSort
}